package com.colorlight.cloud.auth.util;


import java.util.HashMap;
import java.util.Map;

import static com.colorlight.cloud.common.constants.CommonConstants.*;


/**
 * @author Demon
 * 下发主题
 */

public class TopicUtil {
	/**
	 * @param subTopic 上报主题
	 * @author Demon
	 * 根据上报主题解析 DeviceName
	 * up/{productKey}/{deviceName}
	 **/
	
	public static Map<String, String> getTopicInfo(String subTopic) {
		String[] split = subTopic.split(CONNECTOR6);
		final HashMap<String, String> map = new HashMap<>(2);
		map.put(PRODUCT_KEY, split[1]);
		map.put(DEVICE_NAME, split[2]);
		return map;
	}
	
	/**
	 * down/{productKey}/{deviceName}
	 * a.down/ACU35/CLT21232578800
	 *
	 * @param productKey 盒子信息
	 * @param deviceName 设备名
	 * @return 目标主题
	 * @author Demon
	 **/
	
	public static String getPublisherTopic(String productKey, String deviceName) {
		return TOPIC_DOWN +
				CONNECTOR6 +
				productKey +
				CONNECTOR6 +
				deviceName;
	}
}
